/*
 * IC Project - a prototype to test a hypothesis of collective intelligence
 * Copyright (C) 2012 Paolo Conte - paolo@concavi.net
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.ix.data.entities;

import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PeerInfo implements Serializable {

    public String guid;
    public URL url;

    public PeerInfo(String guid, URL url) {
        this.guid = guid;
        this.url = url;
    }

    public PeerInfo(String guid, String host, int port) {
        this.guid = guid;
        try {
            this.url = new URL("http", host, port, "");
        } catch (MalformedURLException ex) {
            Logger.getLogger(PeerInfo.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public PeerInfo(URL url) {
        this(url.getHost() + ":" + url.getPort(), url);
    }

    public String toP2PString() {
        return guid + " " + url.getHost() + ":" + url.getPort();
    }
}
